package cn.gok.tech.baiduocr.service.impl;


import cn.gok.tech.baiduocr.service.OperationService;
import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class OperationImpl implements OperationService {
    //设置APPID/AK/SK
    public static final String APP_ID = "17141601";
    public static final String API_KEY = "uE1NiOLs5is3mCD7xTnB7DDC";
    public static final String SECRET_KEY = "Z9CsnYanCc3k6adUPuGuFAa5eeuGvwx7";

    AipOcr client=null;

    @Override
    public String fontOCR(String imgPath) {
        // 初始化一个AipOcr
        client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("detect_direction", "true");
//        options.put("probability", "true");


        // 参数为本地路径
        String image = imgPath;
        JSONObject res = client.basicAccurateGeneral(image, options);
        return res.toString();
    }
}
